//
//  UIButton+Action.m
//  青旅OA
//
//  Created by qlwl on 16/4/22.
//  Copyright © 2016年 qlwl. All rights reserved.
//

#import "UIButton+Action.h"
#import <objc/runtime.h>

static char btnClickKey;
@implementation UIButton (Action)
- (void) addTarget:(void(^)(UIButton *btn))didClick
{
    [self addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    objc_setAssociatedObject(self, &btnClickKey,didClick, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (void)btnClick:(UIButton *)btn
{
    void (^block)(UIButton *) = (void (^)(UIButton *))objc_getAssociatedObject(self, &btnClickKey);
    if (block) {
        block(btn);
    }
}
@end
